package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
    * ${table.comment!} 前端控制器
    * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Api(tags = "${table.comment}相关接口")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>
    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
    * 根据Id值查询
    *
    * @param id
    * @return
    */
    @ApiOperation("根据Id值查询")
    @GetMapping("/detail")
    public DataResponse detail(String id) {
        return DataResponseBuilder.buildSuccessBody(this.${table.serviceName?uncap_first}.detail(id));
    }

    /**
    * 根据条件查询
    *
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation("根据条件查询")
    @GetMapping("/queryOne")
    public DataResponse queryOne(${entity} ${entity?uncap_first}) {
            SearchConditionBuilder builder = new SearchConditionBuilder().buildExample(${entity?uncap_first});
            return DataResponseBuilder.buildSuccessBody(this.${table.serviceName?uncap_first}
            .queryOne(builder.getCondition()));
    }

    /**
    * 据条件查询数据
    *
    * @param ${entity?uncap_first} 条件
    * @return 查询到的集合列表
    */
    @ApiOperation("列表查询")
    @GetMapping(value = "/queryList")
    public DataResponse queryList(${entity} ${entity?uncap_first}) {
      SearchConditionBuilder builder = new SearchConditionBuilder().buildExample(${entity?uncap_first});
      return DataResponseBuilder.buildSuccessBody(this.${table.serviceName?uncap_first}
                .queryList(builder.getCondition()));
    }

    /**
    * 分页查询
    * @param pageSearch
    * @param ${entity?uncap_first}
    * @return
    */
    @ApiOperation("分页查询")
    @GetMapping(value = "/queryPage")
    public DataResponse queryPage(PageSearch pageSearch, ${entity} ${entity?uncap_first}) {
      SearchConditionBuilder builder = new SearchConditionBuilder().buildExampleAndPage(pageSearch, ${entity?uncap_first});
      return DataResponseBuilder.buildBodyByPageResult(this.${table.serviceName?uncap_first}
                    .queryPage(builder.getCondition()));
    }


    /**
    * 保存对象
    *
    * @param entity 实体对象
    * @return
    */
    @ApiOperation("添加数据")
    @PostMapping(value = "/save")
    public DataResponse save(@Validated @RequestBody ${entity} entity) {
      return DataResponseBuilder.buildBodyByBaseResult(this.${table.serviceName?uncap_first}.save(entity));
    }


    /**
    * 根据实体对象删除数据
    *
    * @param entity 实体对象
    * @return BaseResult 里面的obj对象是影响行数
    */
    @ApiOperation("根据实体对象删除数据")
    @PostMapping(value = "/delete")
    public DataResponse delete(@Validated @RequestBody ${entity} entity) {
    return DataResponseBuilder.buildBodyByBaseResult(this.${table.serviceName?uncap_first}.delete(entity));
    }


    /**
    * 修改部分数据，如果实体对象的某个属性为null则不更新
    *
    * @param entity
    * @return
    */
    @ApiOperation("修改数据")
    @PostMapping(value = "/update")
    public DataResponse update(@Validated @RequestBody ${entity} entity) {
      return DataResponseBuilder.buildBodyByBaseResult(this.${table.serviceName?uncap_first}.update(entity));
    }
}
</#if>
